package com.jf.blog_jf04.utils.exception;

import com.jf.blog_jf04.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
@Slf4j
public class AppExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public R handlerBusinessException(BusinessException e) {
        log.error("business异常：{{}}", e.getMessage());
        return R.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R handlerException(Exception e) {
        log.error("Exception异常：{{}}", e.getMessage());
        e.printStackTrace();
        return R.error(e.getMessage() == null ? e.toString() : e.getMessage());
    }
}
